package edu.mis.modules.accountingReports;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONArray;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

public class ZcfzbController extends Controller{
	public void index() {
		render("zcfzb.html");
	}
	
	/**
	 * 获取资产负债表数据（不重分类）
	 */
	public void get() {
		try {
			JSONArray array = new JSONArray();
			String date = getPara("date");
			String[] strArray = date.split("-");
			String year = strArray[0];
			Map<String, Object> xm = new HashMap<String, Object>();
			double ldzcNcyeSum = 0, ldzcQmyeSum = 0;
			//流动资产
			xm.put("name", "货币资金");
			List<Record> list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (1001,1002,1012)");
			xm.put("ncye", list.get(0).getDouble("openingBalance") + list.get(1).getDouble("openingBalance")
					+ list.get(2).getDouble("openingBalance"));
			ldzcNcyeSum += list.get(0).getDouble("openingBalance") + list.get(1).getDouble("openingBalance")
					+ list.get(2).getDouble("openingBalance");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (1001,1002,1012)");
			double qmye = list.get(0).getDouble("openingBalance") + list.get(0).getDouble("jffs")
					- list.get(0).getDouble("dffs") + list.get(1).getDouble("openingBalance")
					+ list.get(1).getDouble("jffs") - list.get(1).getDouble("dffs")
					+ list.get(2).getDouble("openingBalance") + list.get(2).getDouble("jffs")
					- list.get(2).getDouble("dffs");
			ldzcQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(0, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "短期投资");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (1101)");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			ldzcNcyeSum += list.get(0).getDouble("openingBalance");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (1101)");
			qmye = list.get(0).getDouble("openingBalance") + list.get(0).getDouble("jffs")
					- list.get(0).getDouble("dffs");
			ldzcQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(1, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "应收票据");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (1121)");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			ldzcNcyeSum += list.get(0).getDouble("openingBalance");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (1121)");
			qmye = list.get(0).getDouble("openingBalance") + list.get(0).getDouble("jffs")
					- list.get(0).getDouble("dffs");
			xm.put("qmye", qmye);
			ldzcQmyeSum += qmye;
			array.add(2, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "应收账款");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (1122)");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			ldzcNcyeSum += list.get(0).getDouble("openingBalance");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (1122)");
			qmye = list.get(0).getDouble("openingBalance") + list.get(0).getDouble("jffs")
					- list.get(0).getDouble("dffs");
			ldzcQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(3, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "预付账款");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (1123)");
			ldzcNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (1123)");
			qmye = list.get(0).getDouble("openingBalance") + list.get(0).getDouble("jffs")
					- list.get(0).getDouble("dffs");
			ldzcQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(4, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "应收股利");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (1131)");
			ldzcNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (1131)");
			qmye = list.get(0).getDouble("openingBalance") + list.get(0).getDouble("jffs")
					- list.get(0).getDouble("dffs");
			ldzcQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(5, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "应收利息");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (1132)");
			ldzcNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (1132)");
			qmye = list.get(0).getDouble("openingBalance") + list.get(0).getDouble("jffs")
					- list.get(0).getDouble("dffs");
			ldzcQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(6, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "其他应收款");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (1221)");
			ldzcNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (1221)");
			qmye = list.get(0).getDouble("openingBalance") + list.get(0).getDouble("jffs")
					- list.get(0).getDouble("dffs");
			ldzcQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(7, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "其中：原材料");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (1403)");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			double yclNcye = list.get(0).getDouble("openingBalance");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (1403)");
			qmye = list.get(0).getDouble("openingBalance") + list.get(0).getDouble("jffs")
					- list.get(0).getDouble("dffs");
			double yclQmye = qmye;
			xm.put("qmye", qmye);
			array.add(8, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "其中：在产品");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (5001,5101,5401,5403)");
			double zcpNcye = 0;
			for (int i = 0; i < list.size(); i++) {
				zcpNcye += list.get(i).getDouble("openingBalance");
			}
			xm.put("ncye", zcpNcye);
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (5001,5101,5401,5403)");
			double zcpQmye = 0;
			for (int i = 0; i < list.size(); i++) {
				zcpQmye = zcpQmye + list.get(i).getDouble("openingBalance") + list.get(i).getDouble("jffs")
						- list.get(i).getDouble("dffs");
			}
			xm.put("qmye", zcpQmye);
			array.add(9, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "其中：库存商品");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (1405)");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			double kcspNcye = list.get(0).getDouble("openingBalance");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (1405)");
			qmye = list.get(0).getDouble("openingBalance") + list.get(0).getDouble("jffs")
					- list.get(0).getDouble("dffs");
			double kcspQmye = qmye;
			xm.put("qmye", qmye);
			array.add(10, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "其中：周转材料");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (1411)");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			double zzclNcye = list.get(0).getDouble("openingBalance");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (1411)");
			qmye = list.get(0).getDouble("openingBalance") + list.get(0).getDouble("jffs")
					- list.get(0).getDouble("dffs");
			double zzclQmye = qmye;
			xm.put("qmye", qmye);
			array.add(11, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "存货");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (1401,1402,1404,1408,1421)");
			double chNcye = 0;
			for (int i = 0; i < list.size(); i++) {
				chNcye += list.get(i).getDouble("openingBalance");
			}
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (1407)");
			double spjxcjNcye = list.get(0).getDouble("openingBalance");
			chNcye = chNcye + yclNcye + zcpNcye + zzclNcye + kcspNcye - spjxcjNcye;
			xm.put("ncye", chNcye);
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (1401,1402,1404,1408,1421)");
			double chQmye = 0;
			for (int i = 0; i < list.size(); i++) {
				chQmye = chQmye + list.get(i).getDouble("openingBalance") + list.get(i).getDouble("jffs")
						- list.get(i).getDouble("dffs");
			}
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (1407)");
			double spjxcjQmye = list.get(0).getDouble("openingBalance") + list.get(0).getDouble("jffs")
					- list.get(0).getDouble("dffs");
			chQmye = chQmye + yclQmye + zcpQmye + zzclQmye + kcspQmye - spjxcjQmye;
			xm.put("qmye", chQmye);
			array.add(12, xm);
			ldzcNcyeSum += chNcye;
			ldzcQmyeSum += chQmye;
			
			xm = new HashMap<String, Object>();
			xm.put("name", "其他流动资产");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (1901)");
			ldzcNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (1901)");
			qmye = list.get(0).getDouble("openingBalance") + list.get(0).getDouble("jffs")
					- list.get(0).getDouble("dffs");
			ldzcQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(13, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "流动资产合计");
			xm.put("ncye", ldzcNcyeSum);
			xm.put("qmye", ldzcQmyeSum);
			array.add(14, xm);
			//非流动资产
			double fldzcNcyeSum = 0, fldzcQmyeSum = 0;
			xm = new HashMap<String, Object>();
			xm.put("name", "长期债券投资");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (1501)");
			fldzcNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (1501)");
			qmye = list.get(0).getDouble("openingBalance") + list.get(0).getDouble("jffs")
					- list.get(0).getDouble("dffs");
			fldzcQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(15, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "长期股权投资");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (1511)");
			fldzcNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (1511)");
			qmye = list.get(0).getDouble("openingBalance") + list.get(0).getDouble("jffs")
					- list.get(0).getDouble("dffs");
			fldzcQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(16, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "固定资产原价");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (1601)");
			fldzcNcyeSum += list.get(0).getDouble("openingBalance");
			double gdzcNcye = list.get(0).getDouble("openingBalance");
			xm.put("ncye", gdzcNcye);
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (1601)");
			qmye = list.get(0).getDouble("openingBalance") + list.get(0).getDouble("jffs")
					- list.get(0).getDouble("dffs");
			fldzcQmyeSum += qmye;
			double gdzcQmye = qmye;
			xm.put("qmye", qmye);
			array.add(17, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "减：累计折旧");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (1602)");
			fldzcNcyeSum -= list.get(0).getDouble("openingBalance");
			double ljzjNcye = list.get(0).getDouble("openingBalance");
			xm.put("ncye", ljzjNcye);
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (1602)");
			qmye = list.get(0).getDouble("openingBalance") - list.get(0).getDouble("jffs")
					+ list.get(0).getDouble("dffs");
			fldzcQmyeSum -= qmye;
			double ljzjQmye = qmye;
			xm.put("qmye", qmye);
			array.add(18, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "固定资产账面价值");
			xm.put("ncye", gdzcNcye - ljzjNcye);
			xm.put("qmye", gdzcQmye - ljzjQmye);
			array.add(19, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "在建工程");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (1604)");
			fldzcNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (1604)");
			qmye = list.get(0).getDouble("openingBalance") + list.get(0).getDouble("jffs")
					- list.get(0).getDouble("dffs");
			fldzcQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(20, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "工程物资");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (1605)");
			fldzcNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (1605)");
			qmye = list.get(0).getDouble("openingBalance") + list.get(0).getDouble("jffs")
					- list.get(0).getDouble("dffs");
			fldzcQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(21, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "固定资产清理");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (1606)");
			fldzcNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (1606)");
			qmye = list.get(0).getDouble("openingBalance") + list.get(0).getDouble("jffs")
					- list.get(0).getDouble("dffs");
			fldzcQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(22, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "生产性生物资产");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (1621,1622)");
			double swxzcNcye = list.get(0).getDouble("openingBalance") - list.get(1).getDouble("openingBalance");
			fldzcNcyeSum += swxzcNcye;
			xm.put("ncye", swxzcNcye);
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (1621,1622)");
			double swxzcQmye = list.get(0).getDouble("openingBalance") + list.get(0).getDouble("jffs")
					- list.get(0).getDouble("dffs") - (list.get(1).getDouble("openingBalance")
							- list.get(1).getDouble("jffs") + list.get(1).getDouble("dffs"));
			fldzcQmyeSum += swxzcQmye;
			xm.put("qmye", swxzcQmye);
			array.add(23, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "无形资产");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (1701,1702)");
			double wxzcNcye = list.get(0).getDouble("openingBalance") - list.get(1).getDouble("openingBalance");
			fldzcNcyeSum += wxzcNcye;
			xm.put("ncye", wxzcNcye);
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (1701,1702)");
			double wxzcQmye = list.get(0).getDouble("openingBalance") + list.get(0).getDouble("jffs")
					- list.get(0).getDouble("dffs") - (list.get(1).getDouble("openingBalance")
							- list.get(1).getDouble("jffs") + list.get(1).getDouble("dffs"));
			fldzcQmyeSum += wxzcQmye;
			xm.put("qmye", wxzcQmye);
			array.add(24, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "开发支出");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (5301)");
			fldzcNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (5301)");
			qmye = list.get(0).getDouble("openingBalance") + list.get(0).getDouble("jffs")
					- list.get(0).getDouble("dffs");
			fldzcQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(25, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "长期待摊费用");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (1801)");
			fldzcNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (1801)");
			qmye = list.get(0).getDouble("openingBalance") + list.get(0).getDouble("jffs")
					- list.get(0).getDouble("dffs");
			fldzcQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(26, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "其他非流动资产");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (1901)");
			fldzcNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (1901)");
			qmye = list.get(0).getDouble("openingBalance") + list.get(0).getDouble("jffs")
					- list.get(0).getDouble("dffs");
			fldzcQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(27, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "非流动资产合计");
			xm.put("ncye", fldzcNcyeSum);
			xm.put("qmye", fldzcQmyeSum);
			array.add(28, xm);
			
			//资产合计
			xm = new HashMap<String, Object>();
			xm.put("name", "资产合计");
			xm.put("ncye", ldzcNcyeSum + fldzcNcyeSum);
			xm.put("qmye", ldzcQmyeSum + fldzcQmyeSum);
			array.add(29, xm);
			
			//流动负债
			double ldfzNcyeSum = 0, ldfzQmyeSum = 0;
			xm = new HashMap<String, Object>();
			xm.put("name", "短期借款");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (2001)");
			ldfzNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (2001)");
			qmye = list.get(0).getDouble("openingBalance") - list.get(0).getDouble("jffs")
					+ list.get(0).getDouble("dffs");
			ldfzQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(30, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "应付票据");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (2201)");
			ldfzNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (2201)");
			qmye = list.get(0).getDouble("openingBalance") - list.get(0).getDouble("jffs")
					+ list.get(0).getDouble("dffs");
			ldfzQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(31, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "应付账款");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (2202)");
			ldfzNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (2202)");
			qmye = list.get(0).getDouble("openingBalance") - list.get(0).getDouble("jffs")
					+ list.get(0).getDouble("dffs");
			ldfzQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(32, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "预收账款");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (2203)");
			ldfzNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (2203)");
			qmye = list.get(0).getDouble("openingBalance") - list.get(0).getDouble("jffs")
					+ list.get(0).getDouble("dffs");
			ldfzQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(33, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "应付职工薪酬");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (2211)");
			ldfzNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (2211)");
			qmye = list.get(0).getDouble("openingBalance") - list.get(0).getDouble("jffs")
					+ list.get(0).getDouble("dffs");
			ldfzQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(34, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "应交税费");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (2221)");
			ldfzNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (2221)");
			qmye = list.get(0).getDouble("openingBalance") - list.get(0).getDouble("jffs")
					+ list.get(0).getDouble("dffs");
			ldfzQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(35, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "应付利息");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (2231)");
			ldfzNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (2231)");
			qmye = list.get(0).getDouble("openingBalance") - list.get(0).getDouble("jffs")
					+ list.get(0).getDouble("dffs");
			ldfzQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(36, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "应付利润");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (2232)");
			ldfzNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (2232)");
			qmye = list.get(0).getDouble("openingBalance") - list.get(0).getDouble("jffs")
					+ list.get(0).getDouble("dffs");
			ldfzQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(37, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "其他应付款");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (2241)");
			ldfzNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (2241)");
			qmye = list.get(0).getDouble("openingBalance") - list.get(0).getDouble("jffs")
					+ list.get(0).getDouble("dffs");
			ldfzQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(38, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "其他流动负债");
			xm.put("ncye", 0);
			xm.put("qmye", 0);
			array.add(39, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "流动负债合计");
			xm.put("ncye", ldfzNcyeSum);
			xm.put("qmye", ldfzQmyeSum);
			array.add(40, xm);
			
			//非流动负债
			double fldfzNcyeSum = 0, fldfzQmyeSum = 0;
			xm = new HashMap<String, Object>();
			xm.put("name", "长期借款");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (2501)");
			fldfzNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (2501)");
			qmye = list.get(0).getDouble("openingBalance") - list.get(0).getDouble("jffs")
					+ list.get(0).getDouble("dffs");
			fldfzQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(41, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "长期应付款");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (2701)");
			fldfzNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (2701)");
			qmye = list.get(0).getDouble("openingBalance") - list.get(0).getDouble("jffs")
					+ list.get(0).getDouble("dffs");
			fldfzQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(42, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "递延收益");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (2401)");
			fldfzNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (2401)");
			qmye = list.get(0).getDouble("openingBalance") - list.get(0).getDouble("jffs")
					+ list.get(0).getDouble("dffs");
			fldfzQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(43, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "其他非流动负债");
			xm.put("ncye", 0);
			xm.put("qmye", 0);
			array.add(44, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "非流动负债合计");
			xm.put("ncye", fldfzNcyeSum);
			xm.put("qmye", fldfzQmyeSum);
			array.add(45, xm);
			
			//负债合计
			xm = new HashMap<String, Object>();
			xm.put("name", "负债合计");
			xm.put("ncye", ldfzNcyeSum + fldfzNcyeSum);
			xm.put("qmye", ldfzQmyeSum + fldfzQmyeSum);
			array.add(46, xm);
			
			//所有者权益
			double syzqyNcyeSum = 0, syzqyQmyeSum = 0;
			xm = new HashMap<String, Object>();
			xm.put("name", "实收资本（或股本）");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (4001)");
			syzqyNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (4001)");
			qmye = list.get(0).getDouble("openingBalance") - list.get(0).getDouble("jffs")
					+ list.get(0).getDouble("dffs");
			syzqyQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(47, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "资本公积");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (4002)");
			syzqyNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (4002)");
			qmye = list.get(0).getDouble("openingBalance") - list.get(0).getDouble("jffs")
					+ list.get(0).getDouble("dffs");
			syzqyQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(48, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "盈余公积");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (4101)");
			syzqyNcyeSum += list.get(0).getDouble("openingBalance");
			xm.put("ncye", list.get(0).getDouble("openingBalance"));
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (4101)");
			qmye = list.get(0).getDouble("openingBalance") - list.get(0).getDouble("jffs")
					+ list.get(0).getDouble("dffs");
			syzqyQmyeSum += qmye;
			xm.put("qmye", qmye);
			array.add(49, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "未分配利润");
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + year
					+ "-01' and isInit = 0 and captionId in (4103,4104)");
			double wfplrNcye = list.get(0).getDouble("openingBalance") + list.get(1).getDouble("openingBalance");
			syzqyNcyeSum += wfplrNcye;
			xm.put("ncye", wfplrNcye);
			list = Db.find("select * from kmye where date_format(date,'%Y-%m')='" + date
					+ "' and isInit = 0 and captionId in (4103,4104)");
			double wfplrQmye = 0;
			for (int i = 0; i < list.size(); i++) {
				wfplrQmye = wfplrQmye + list.get(i).getDouble("openingBalance") - list.get(i).getDouble("jffs")
						+ list.get(i).getDouble("dffs");
			}
			syzqyQmyeSum += wfplrQmye;
			xm.put("qmye", wfplrQmye);
			array.add(50, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "所有者权益（或股东权益）合计");
			xm.put("ncye", syzqyNcyeSum);
			xm.put("qmye", syzqyQmyeSum);
			array.add(51, xm);
			
			xm = new HashMap<String, Object>();
			xm.put("name", "负债和所有者权益（或股东权益）合计");
			xm.put("ncye", ldfzNcyeSum + fldfzNcyeSum + syzqyNcyeSum);
			xm.put("qmye", ldfzQmyeSum + fldfzQmyeSum + syzqyQmyeSum);
			array.add(52, xm);
			
			renderJson(array.toJSONString());
		} catch (Exception e) {
			// TODO: handle exception
			setAttr("success", false);
			setAttr("msg", "查询失败!");
			renderJson();
		}
	}
}
